package cn.zmit.kuxi.widget;

import cn.zmit.kuxi.R;
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/** * @author   @parameter  * @return  */
public class TitleBar extends LinearLayout {
	private RelativeLayout mRoot,rl_back;
	private ImageView ima_back;
	private TextView tv_back,tv_title;
	private OnImageBackClickListener onImageBackClickListener;

	
	public RelativeLayout getRl_back() {
		return rl_back;
	}

	public ImageView getIma_back() {
		return ima_back;
	}

	public TextView getTv_back() {
		return tv_back;
	}

	public TextView getTv_title() {
		return tv_title;
	}

	public TitleBar(Context context) {
		super(context);
		initView(context);
	}
	
	public TitleBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}

	public TitleBar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initView(context);
	}
	private void initView(final Context context) {
		View view=View.inflate(context, R.layout.view_titlebar, this);
		mRoot=(RelativeLayout)view.findViewById(R.id.rl_root);
		rl_back=(RelativeLayout)view.findViewById(R.id.rl_back);
		tv_title=(TextView)view.findViewById(R.id.tv_titlebar_title);
		ima_back=(ImageView)view.findViewById(R.id.imag_back);
		tv_back=(TextView)view.findViewById(R.id.tv_back);
		rl_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (onImageBackClickListener != null) {
					onImageBackClickListener.onImageBackClick();
				} else {
					Activity activity = (Activity) context;
					activity.finish();
				}
			}
		});
	}
	//添加右侧按钮
	public void addRightView(View view){
		RelativeLayout.LayoutParams rightParams=new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.MATCH_PARENT	
				);
		rightParams.addRule(RelativeLayout.CENTER_VERTICAL);
		rightParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		mRoot.addView(view, rightParams);
	}
	/**
	 * 设置返回按钮点击回调
	 * 
	 * @param onImageBackClickListener
	 *          
	 */
	public void setOnRippImageBackClickListener(
			OnImageBackClickListener onImageBackClickListener) {
		this.onImageBackClickListener = onImageBackClickListener;
	}
	/**
	 * 返回按钮点击回调
	 
	 */
	public interface OnImageBackClickListener {
		public void onImageBackClick();
	}

	
	
}
